package com.wenshi.common.core.domain;

import io.netty.buffer.ByteBuf;
import lombok.Data;

@Data
public class ModbusFrame {
    /**
     * 事务标识符(Transaction Identifier)
     * 0000   - 协议标识符(Protocol Identifier)
     * 0009   - 长度字段(Length field)
     * 01     - 单元标识符(Unit Identifier)
     * 03     - 功能码(Function Code)
     * 06     - 字节计数(Byte count)
     * 0000   - 数据(Register Value 1)
     * 0000   - 数据(Register Value 2)
     * 0000   - 数据(Register Value 3)
     */
    private final int transactionId;
    /**
     * - 协议标识符(Protocol Identifier)
     */
    private final int protocolId;
    /**
     * - 长度字段(Length field)
     */
    private final int length;
    /**
     * - 单元标识符(Unit Identifier)
     */
    private final int unitId;
    /**
     * - 功能码(Function Code)
     */
    private final byte functionCode;
    /**
     * - 字节计数(Byte count)+数据
     */
    private final ByteBuf data;

    public ModbusFrame(int transactionId, int protocolId, int length, int unitId, byte functionCode, ByteBuf data) {
        this.transactionId = transactionId;
        this.protocolId = protocolId;
        this.length = length;
        this.unitId = unitId;
        this.functionCode = functionCode;
        this.data = data.retain();
    }
}
